package main.java;

import java.util.Enumeration;
import java.util.Hashtable;

import org.json.JSONException;
import org.json.JSONObject;


public class CardInstance implements Comparable<CardInstance> {
	private static Hashtable<String, String> formation = new Hashtable();
	public int DiscardValue;
	public String Formation;
	public long Id;
	public String ItemState;
	public String ItemType;
	public int Owners;
	public String PreferredPosition;
	public StatsCard StatsCard;
	public long Timestamp;
	private boolean duplicate;

	static {
		formation.put("f3412", "3-4-1-2");
		formation.put("f3421", "3-4-2-1");
		formation.put("f343", "3-4-3");
		formation.put("f352", "3-5-2");
		formation.put("f41212", "4-1-2-1-2");
		formation.put("f4222", "4-2-2-2");
		formation.put("f4231", "4-2-3-1");
		formation.put("f4312", "4-3-1-2");
		formation.put("f4321", "4-3-2-1");
		formation.put("f433", "4-3-3");
		formation.put("f4411", "4-4-1-1");
		formation.put("f442", "4-4-2");
		formation.put("f451", "4-5-1");
		formation.put("f5212", "5-2-1-2");
		formation.put("f5221", "5-2-2-1");
		formation.put("f532", "5-3-2");
	}

	public CardInstance(JSONObject paramJSONObject) throws JSONException {
		this.Id = paramJSONObject.getLong("id");
		this.ItemState = paramJSONObject.getString("itemState").intern();
		this.ItemType = paramJSONObject.getString("itemType").intern();
		this.Owners = paramJSONObject.optInt("owners", 0);
		this.DiscardValue = paramJSONObject.optInt("discardValue", 0);
		this.Formation = "";
		this.PreferredPosition = "";
		if (this.ItemType == "player")
			this.PreferredPosition = paramJSONObject.getString(
					"preferredPosition").intern();
		if ((this.ItemType == "player") || (this.ItemType == "manager"))
			this.Formation = ((String) formation.get(paramJSONObject
					.getString("formation")));
		this.StatsCard = new StatsCard();
		this.StatsCard.ResourceId = paramJSONObject.getInt("resourceId");
	}

	public static String getFormationCode(String paramString) {
		Enumeration<String> localEnumeration = formation.keys();
		String str;
		if (!localEnumeration.hasMoreElements())
			str = paramString;
		while (true) {
			return str;
			str = (String) localEnumeration.nextElement();
			if (!((String) formation.get(str)).equals(paramString))
				break;
		}
	}

	public static String getFormationText(String paramString) {
		return (String) formation.get(paramString);
	}

	public int compareTo(CardInstance paramCardInstance) {
  int i = 1;
  int j;
  int i2;
  if (paramCardInstance.isDuplicate())
  {
    j = i;
    if (!isDuplicate())
      break label40;
    int k = j - i;
    if (k == 0)
      break label45;
    i2 = k;
  }
  while (true)
  {
    return i2;
    j = 0;
    break;
    label40: i = 0;
    break label18;
    int m = this.StatsCard.Rating - paramCardInstance.StatsCard.Rating;
    if (m != 0)
    {
      i2 = m;
    }
    else
    {
      int n = this.StatsCard.Rare - paramCardInstance.StatsCard.Rare;
      if (n != 0)
      {
        i2 = n;
      }
      else
      {
        int i1 = this.StatsCard.ResourceId - paramCardInstance.StatsCard.ResourceId;
        if (i1 != 0)
          i2 = i1;
        else
          i2 = (int)(this.Id - paramCardInstance.Id);
      }
    }
  }
}

	public boolean isConsumable() {
		if ("contract health training".indexOf(this.ItemType) >= 0)
			;
		for (boolean bool = true;; bool = false)
			return bool;
	}

	public boolean isDuplicate() {
		if ((this.duplicate) && (!isConsumable()))
			;
		for (boolean bool = true;; bool = false)
			return bool;
	}

	public boolean isPlayer() {
		if (this.ItemType == "player")
			;
		for (boolean bool = true;; bool = false)
			return bool;
	}

	public void setDuplicate(boolean paramBoolean) {
		this.duplicate = (paramBoolean | this.duplicate);
	}
}